package test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class Main {
    static String schema = "sys";

    public static void main(String[] args) {
        try {
            Map<String, String> constraints = new HashMap<>();
            constraints.put("useSSL", String.valueOf(false));
            constraints.put("serverTimeZone", "UTC");
            String url = SQLFormatter.url(3306, schema, constraints);
            System.out.println(url);
            Connection connection = DriverManager.getConnection(url, "root", "usstcec");
            System.out.println("open success");

            PreparedStatement query = connection.prepareStatement("SELECT * FROM mytest.test1");



            ResultSet set = query.executeQuery();
            while (set.next()) {
                System.out.println(set.getString("name")+"\t"+set.getString("pw"));
            }
            String nameADD="1",passwordADD="1";
            String sql = "INSERT INTO `mytest`.`test1` (`name`, `pw`) "
                    +"VALUES ('"+nameADD+"', '"+passwordADD+"');";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            if (preparedStatement.executeUpdate() == 0)
                System.out.println("Write Error");
            else System.out.println("Update Success");
            connection.close();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}